var e = require("../../@babel/runtime/helpers/interopRequireDefault").default;

Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.default = void 0;

var t = require("../../@babel/runtime/helpers/classCallCheck"), n = require("../../@babel/runtime/helpers/createClass"), i = e(require("./weapp.default.config")), r = function(e) {
    for (var t = getCurrentPages() || [], n = "", i = (t[t.length - 1] || {}).options, r = void 0 === i ? {} : i, o = Object.keys(r), s = 0; s < o.length; s++) if (o[s].toLowerCase() === e.toLowerCase()) return n = r[o[s]];
    return n;
}, o = function e(t, n) {
    return Object.keys(n).forEach(function(i) {
        var r, o = n[i];
        Object.prototype.hasOwnProperty.call(t, i) && (r = o, Object.prototype.toString.call(r).indexOf("Object") > -1) ? t[i] = e(t[i], o) : Array.isArray(o) ? t[i] = o.map(function(e) {
            return e;
        }) : t[i] = o;
    }), t;
}, s = function(e) {
    return "function" == typeof e;
}, a = function(e, t) {
    var n, i, r = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""), o = [];
    if (t = t || r.length, e) for (n = 0; n < e; n++) o[n] = r[0 | Math.random() * t]; else for (o[8] = o[13] = o[18] = o[23] = "-", 
    o[14] = "4", n = 0; n < 36; n++) o[n] || (i = 0 | 16 * Math.random(), o[n] = r[19 === n ? 3 & i | 8 : i]);
    return o.join("");
}, u = {
    1000: "其他",
    1001: "发现栏小程序主入口，「最近使用」列表（基础库2.2.4版本起包含「我的小程序」列表）",
    1005: "顶部搜索框的搜索结果页",
    1006: "发现栏小程序主入口搜索框的搜索结果页",
    1007: "单人聊天会话中的小程序消息卡片",
    1008: "群聊会话中的小程序消息卡片",
    1011: "扫描二维码",
    1012: "长按图片识别二维码",
    1013: "手机相册选取二维码",
    1014: "小程序模版消息",
    1017: "前往体验版的入口页",
    1019: "微信钱包",
    1020: "公众号 profile 页相关小程序列表",
    1022: "聊天顶部置顶小程序入口",
    1023: "安卓系统桌面图标",
    1024: "小程序 profile 页",
    1025: "扫描一维码",
    1026: "附近小程序列表",
    1027: "顶部搜索框搜索结果页“使用过的小程序”列表",
    1028: "我的卡包",
    1029: "卡券详情页",
    1030: "自动化测试下打开小程序",
    1031: "长按图片识别一维码",
    1032: "手机相册选取一维码",
    1034: "微信支付完成页",
    1035: "公众号自定义菜单",
    1036: "App 分享消息卡片",
    1037: "小程序打开小程序",
    1038: "从另一个小程序返回",
    1039: "摇电视",
    1042: "添加好友搜索框的搜索结果页",
    1043: "公众号模板消息",
    1044: "带 shareTicket 的小程序消息卡片（详情)",
    1045: "朋友圈广告",
    1046: "朋友圈广告详情页",
    1047: "扫描小程序码",
    1048: "长按图片识别小程序码",
    1049: "手机相册选取小程序码",
    1052: "卡券的适用门店列表",
    1053: "搜一搜的结果页",
    1054: "顶部搜索框小程序快捷入口",
    1056: "音乐播放器菜单",
    1057: "钱包中的银行卡详情页",
    1058: "公众号文章",
    1059: "体验版小程序绑定邀请页",
    1064: "微信连Wi-Fi状态栏",
    1067: "公众号文章广告",
    1068: "附近小程序列表广告",
    1069: "移动应用",
    1071: "钱包中的银行卡列表页",
    1072: "二维码收款页面",
    1073: "客服消息列表下发的小程序消息卡片",
    1074: "公众号会话下发的小程序消息卡片",
    1077: "摇周边",
    1078: "连Wi-Fi成功页",
    1079: "微信游戏中心",
    1081: "客服消息下发的文字链",
    1082: "公众号会话下发的文字链",
    1084: "朋友圈广告原生页",
    1088: "会话中查看系统消息，打开小程序",
    1089: "微信聊天主界面下拉",
    1090: "长按小程序右上角菜单唤出最近使用历史",
    1091: "公众号文章商品卡片",
    1092: "城市服务入口",
    1095: "小程序广告组件",
    1096: "聊天记录",
    1097: "微信支付签约页",
    1099: "页面内嵌插件",
    1102: "公众号 profile 页服务预览",
    1103: "发现栏小程序主入口，“我的小程序”列表",
    1104: "微信聊天主界面下拉，“我的小程序”栏",
    1106: "聊天主界面下拉，从顶部搜索结果页，打开小程序",
    1107: "订阅消息，打开小程序",
    1113: "安卓手机负一屏，打开小程序(三星)",
    1114: "安卓手机侧边栏，打开小程序(三星)",
    1124: "扫“一物一码”打开小程序",
    1125: "长按图片识别“一物一码”",
    1126: "扫描手机相册中选取的“一物一码”",
    1129: "微信爬虫访问",
    1131: "浮窗打开小程序",
    1146: "地理位置信息打开出行类小程序",
    1148: "卡包-交通卡，打开小程序"
}, c = function() {
    function e(n) {
        t(this, e), this.baseExt = {
            version: "weapp_1.0.3"
        }, this.config = o(i.default, n), this.appid = this.config.appid, this.getDevice(), 
        this.setSi(), this.setPvi();
    }
    return n(e, [ {
        key: "getBaseFields",
        value: function() {
            this.getBaseUserInfo();
            var e = this.appid, t = this.si, n = this.pvi;
            return Object.assign(this.deviceMsg, {
                id3Rd: this.userInfo.openid,
                r2: e,
                si: t,
                pvi: n,
                random: Date.now(),
                adt: r("adtag") || r("ADTAG") || void 0,
                ext: this.getExtString()
            });
        }
    }, {
        key: "setSi",
        value: function() {
            var e = wx.getStorageSync("pgv_si");
            this.si || (e = a() + Date.now(), wx.setStorageSync("pgv_si", e)), this.si = e;
        }
    }, {
        key: "setPvi",
        value: function() {
            var e = wx.getStorageSync("pgv_pvi");
            e || (e = a() + Date.now(), wx.setStorageSync("pgv_pvi", e)), this.pvi = e;
        }
    }, {
        key: "getDevice",
        value: function() {
            var e = wx.getSystemInfoSync(), t = e.language, n = e.screenWidth, i = e.screenHeight, r = e.brand, o = e.model, s = e.system, a = e.SDKVersion;
            this.deviceMsg = {
                lg: t,
                scr: n + "x" + i,
                tz: new Date().getTimezoneOffset() / 60
            }, this.baseExt = Object.assign(this.baseExt, {
                brand: r,
                model: o,
                system: s,
                SDKVersion: a
            });
        }
    }, {
        key: "getBaseUserInfo",
        value: function() {
            this.userInfo && this.userInfo.unionid || (this.userInfo = {
                openid: wx.getStorageSync("openid"),
                unionid: wx.getStorageSync("unionid")
            }, this.baseExt = Object.assign(this.baseExt, {
                unionid: this.userInfo.unionid
            }));
        }
    }, {
        key: "report",
        value: function(e) {
            var t = this.config, n = t.requestUrl, i = t.requestHeader, r = void 0 === i ? {
                "content-type": "application/x-www-form-urlencoded"
            } : i, o = t.requestMethod, s = void 0 === o ? "POST" : o;
            wx.request({
                method: s,
                url: n,
                header: r,
                data: e,
                success: function(e) {
                    200 !== e.statusCode && console.log("埋点请求返回".concat(e.stausCode));
                },
                fail: function(e) {
                    console.log(e), console.log("埋点请求失败");
                }
            });
        }
    }, {
        key: "clickStat",
        value: function(e) {
            var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
            if (this.testAppid()) {
                var n = Object.assign(this.getBaseFields(), {
                    dm: "ktaclick",
                    url: e.toString().toLowerCase(),
                    ext: this.getExtString(t)
                });
                this.report(n);
            }
        }
    }, {
        key: "getExtString",
        value: function(e) {
            var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "", n = Object.assign(this.baseExt, e || {});
            return Object.keys(n).map(function(e) {
                return "".concat(encodeURIComponent(t + e), "=").concat(encodeURIComponent(n[e]));
            }).join(";");
        }
    }, {
        key: "pvuvStat",
        value: function() {
            var e = getCurrentPages() || [];
            if (!(e.length <= 0)) {
                var t = e.pop() || {}, n = e.pop() || {};
                if (this.testAppid()) {
                    var i = this.config.pageTitleMap, r = t.route, s = t.options, a = n.route, u = n.options, c = i[r] || r, p = i[a] || a || "", g = function(e) {
                        return Object.keys(e).map(function(t) {
                            return "".concat(encodeURIComponent(t), "=").concat(encodeURIComponent(e[t]));
                        }).join("&");
                    }, l = o(this.getBaseFields(), {
                        dm: "pvuv",
                        url: r || "",
                        arg: s ? g(s) : "",
                        rarg: u ? g(u) : "",
                        rurl: a || "",
                        title: c,
                        referTitle: p
                    });
                    this.report(l);
                }
            }
        }
    }, {
        key: "dmStat",
        value: function(e) {
            var t = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, n = o(this.getBaseFields(), {
                dm: e,
                ext: this.getExtString(t)
            });
            this.report(n);
        }
    }, {
        key: "testAppid",
        value: function() {
            var e = this.config.appid;
            return !e && console.log("KTA H5分析错误提示：您没有设置appid"), !!e;
        }
    }, {
        key: "getScene",
        value: function(e) {
            return "number" == typeof e || "string" == typeof e && "" !== e ? (e = String(e), 
            u[e] || e) : "未取到值";
        }
    }, {
        key: "getAutoTrackConfig",
        value: function(e) {
            return !!this.config.autoTrack && this.config.autoTrack[e];
        }
    }, {
        key: "globalWrapper",
        value: function(e) {
            var t = this, n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, i = arguments.length > 2 ? arguments[2] : void 0, r = this.getAutoTrackConfig(e);
            return Object.keys(r).forEach(function(e) {
                var i = n[e], o = r[e], a = t;
                n[e] = function(t) {
                    var n;
                    return i && s(i) && (n = i.apply(this, t)), "pvuv" === o.dm ? a.pvuvStat() : a.dmStat(o.dm || e), 
                    n;
                };
            }), i(n);
        }
    }, {
        key: "Page",
        value: function(e) {
            function t() {
                return e.apply(this, arguments);
            }
            return t.toString = function() {
                return e.toString();
            }, t;
        }(function() {
            var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
            return this.globalWrapper("Page", e, Page);
        })
    }, {
        key: "App",
        value: function(e) {
            function t() {
                return e.apply(this, arguments);
            }
            return t.toString = function() {
                return e.toString();
            }, t;
        }(function() {
            var e = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
            return this.globalWrapper("App", e, App);
        })
    } ]), e;
}();

exports.default = c;